package com.apes.scm.account.account.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.voucher.model.Voucher;
import com.apes.scm.voucher.model.VoucherItem;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 功能：商品价值库存条目
 *
 * @author xul
 * @create 2018-10-17 14:38
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = InventoryBatchEntry.CONST_TABLE_NAME)
public class InventoryBatchEntry extends BaseModel {
    public static final String CONST_TABLE_NAME = "acc_inventory_batch_entry";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "商品价值库存条目")
    private long id;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "voucher_id", referencedColumnName = "id", nullable = false)
    @Comment("凭证编码")
    private Voucher voucher;  //凭证

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "voucher_item_id", referencedColumnName = "id", nullable = false)
    @Comment("凭证明细编码")
    private VoucherItem voucherItem;  //凭证明细

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "inventory_id", referencedColumnName = "id")
    @Comment("商品库存价值编码（批次编码)")
    private InventoryBatch inventoryBatch; //商品库存价值

    @Column(name = "purchase_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("发生数量")
    private double qty = 0.0;  //发生数量

    @Column(name = "book_date")
    @Comment("记账日期")
    private Date bookDate = new Date();  //记账日期

    @Column(name = "record_date")
    @Comment("登记日期")
    private Date recordDate = new Date();  //登记日期

}
